bad41e5d51ab58e8480c89010fd618768614301c,opennms-services/src/main/java/org/opennms/netmgt/capsd/SuspectEventProcessor.java,SuspectEventProcessor,addIfTableSnmpInterfaces,#Connection#InetAddress#number#IfCollector#,858
Before Change
boolean addedSnmpInterfaceEntry = false;
List<IfTableEntry> ifTableEntries = snmpc.getIfTable().getEntries();
for (IfTableEntry ifte : ifTableEntries) {
// index
Integer sint = ifte.getIfIndex();
if (sint == null) {
continue;
}
int xifIndex = sint.intValue();
/*
* address WARNING: IfSnmpCollector.getIfAddressAndMask() ONLY
* returns the FIRST IP address and mask for a given interface as
* specified in the ipAddrTable.
*/
InetAddress[] aaddrs = null;
if (snmpc.hasIpAddrTable()) {
aaddrs = snmpc.getIfAddressAndMask(sint.intValue());
}
if (aaddrs == null) {
/*
* Must be non-IP interface, set ifAddress to
* '0.0.0.0' and mask to null
*/
aaddrs = new InetAddress[2];
try {
aaddrs[0] = InetAddress.getByName("0.0.0.0");
} catch (UnknownHostException e) {
continue;
}
aaddrs[1] = null;
}
// Retrieve ifType so we can check for loopback
sint = ifte.getIfType();
// FIXME: What if sint is null?
int ifType = sint.intValue();
// Skip loopback interfaces
if (aaddrs[0].getHostAddress().startsWith("127.")) {
continue;
}
DbSnmpInterfaceEntry snmpEntry =
DbSnmpInterfaceEntry.create(nodeId, xifIndex);
// IP address
snmpEntry.setIfAddress(aaddrs[0]);
if (aaddrs[0].equals(ifaddr)) {
addedSnmpInterfaceEntry = true;
}
// netmask
if (aaddrs[1] != null) {
snmpEntry.setNetmask(aaddrs[1]);
}
// description
String str = ifte.getIfDescr();
if (log().isDebugEnabled()) {
log().debug("SuspectEventProcessor: "
+ aaddrs[0].getHostAddress() + " has ifDescription: "
+ str);
}
if (str != null && str.length() > 0) {
snmpEntry.setDescription(str);
}
// physical address
String physAddr = ifte.getPhysAddr();
if (log().isDebugEnabled()) {
log().debug("SuspectEventProcessor: "
+ aaddrs[0].getHostAddress()
+ " has physical address: -" + physAddr + "-");
}
if (physAddr != null && physAddr.length() == 12) {
snmpEntry.setPhysicalAddress(physAddr);
}
// type
snmpEntry.setType(ifType);
// speed
Long uint = ifte.getIfSpeed();
if (uint == null) {
snmpEntry.setSpeed(0);
} else {
snmpEntry.setSpeed(uint.longValue());
}
// admin status
sint = ifte.getIfAdminStatus();
if (sint == null) {
snmpEntry.setAdminStatus(0);
} else {
snmpEntry.setAdminStatus(sint.intValue());
}
// oper status
sint = ifte.getIfOperStatus();
if (sint == null) {
snmpEntry.setOperationalStatus(0);
} else {
After Change
boolean addedSnmpInterfaceEntry = false;
for (IfTableEntry ifte : snmpc.getIfTable().getEntries()) {
// index
if (ifte.getIfIndex() == null) {
continue;
}
final int xifIndex = ifte.getIfIndex().intValue();
/*
* address WARNING: IfSnmpCollector.getIfAddressAndMask() ONLY
* returns the FIRST IP address and mask for a given interface as
* specified in the ipAddrTable.
*/
InetAddress[] aaddrs = null;
if (snmpc.hasIpAddrTable()) {
aaddrs = snmpc.getIfAddressAndMask(xifIndex);
}
if (aaddrs == null) {
/*
* Must be non-IP interface, set ifAddress to
* '0.0.0.0' and mask to null
*/
aaddrs = new InetAddress[2];
try {
aaddrs[0] = InetAddress.getByName("0.0.0.0");
} catch (UnknownHostException e) {
continue;
}
aaddrs[1] = null;
}
// At some point back in the day this was done with ifType
// Skip loopback interfaces
if (aaddrs[0].getHostAddress().startsWith("127.")) {
continue;
}
final DbSnmpInterfaceEntry snmpEntry =
DbSnmpInterfaceEntry.create(nodeId, xifIndex);
// IP address
snmpEntry.setIfAddress(aaddrs[0]);
if (aaddrs[0].equals(ifaddr)) {
addedSnmpInterfaceEntry = true;
}
// netmask
if (aaddrs[1] != null) {
snmpEntry.setNetmask(aaddrs[1]);
}
// description
final String str = ifte.getIfDescr();
if (log().isDebugEnabled()) {
log().debug("SuspectEventProcessor: "
+ aaddrs[0].getHostAddress() + " has ifDescription: "
+ str);
}
if (str != null && str.length() > 0) {
snmpEntry.setDescription(str);
}
// physical address
final String physAddr = ifte.getPhysAddr();
if (log().isDebugEnabled()) {
log().debug("SuspectEventProcessor: "
+ aaddrs[0].getHostAddress()
+ " has physical address: -" + physAddr + "-");
}
if (physAddr != null && physAddr.length() == 12) {
snmpEntry.setPhysicalAddress(physAddr);
}
if (ifte.getIfType() == null) {
snmpEntry.setType(0);
} else {
snmpEntry.setType(ifte.getIfType().intValue());
}
// speed
if (ifte.getIfSpeed() == null) {
snmpEntry.setSpeed(0);
} else {
snmpEntry.setSpeed(ifte.getIfSpeed().longValue());
}
// admin status
if (ifte.getIfAdminStatus() == null) {
snmpEntry.setAdminStatus(0);
} else {
snmpEntry.setAdminStatus(ifte.getIfAdminStatus().intValue());
}
// oper status
if (ifte.getIfOperStatus() == null) {
snmpEntry.setOperationalStatus(0);
} else {
snmpEntry.setOperationalStatus(ifte.getIfOperStatus().intValue());
}
// name (from interface extensions table)